<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>跳转中...</title>
    <style>
        body {
            background-color: #f5f5f5;
            font-family: Arial, sans-serif;
        }
        .loading {
            text-align: center;
            margin-top: 20%;
        }
        .loading h2 {
            color: #333;
            margin-bottom: 20px;
        }
        .spinner {
            width: 40px;
            height: 40px;
            margin: 0 auto;
            border: 4px solid #f3f3f3;
            border-top: 4px solid #3498db;
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
    </style>
    <script src="/app/admin/component/layui/layui.js"></script>
    <script>
        layui.use(['jquery'], function() {
            var $ = layui.$;
            
            // 从URL参数中获取目标地址
            function getRedirectUrl() {
                var urlParams = new URLSearchParams(window.location.search);
                return urlParams.get('redirect');
            }
            
            // 检查并初始化必要的会话数据
            function initSession(callback) {
                $.get('/app/ky_shouyin/admin/account/checkSession', function(res) {
                    if(res.code === 0) {
                        // 会话有效，确保必要的会话数据已设置
                        callback(true);
                    } else {
                        callback(false);
                    }
                });
            }
            
            // 执行跳转
            function doRedirect() {
                console.log('Starting redirect process...');
                initSession(function(isValid) {
                    console.log('Session check result:', isValid);
                    if(isValid) {
                        var redirectUrl = getRedirectUrl();
                        console.log('Redirect URL:', redirectUrl);
                        if (redirectUrl) {
                            // 如果是完整URL，直接使用
                            if (redirectUrl.startsWith('http')) {
                                console.log('Using full URL:', redirectUrl);
                                window.location.href = decodeURIComponent(redirectUrl);
                            } else {
                                // 如果是相对路径，添加域名
                                var fullUrl = window.location.origin + decodeURIComponent(redirectUrl);
                                console.log('Using constructed URL:', fullUrl);
                                window.location.href = fullUrl;
                            }
                        } else {
                            console.log('No redirect URL, using default');
                            window.location.href = '/app/ky_shouyin/front/cashier/index';
                        }
                    } else {
                        console.log('Session invalid, redirecting to login');
                        window.location.href = '/app/ky_shouyin/admin/account/userlogin';
                    }
                });
            }
            
            // 页面加载完成后执行跳转
            $(document).ready(function() {
                console.log('Document ready, preparing redirect...');
                // 增加延迟时间，确保动画效果可见
                setTimeout(doRedirect, 1000);
            });
        });
    </script>
</head>
<body>
    <div class="loading">
        <h2>正在跳转...</h2>
        <div class="spinner"></div>
    </div>
</body>
</html> 